<?php

header("Access-Control-Allow-Origin:*");
/*
  版本1
  2.教师获取学生点名数目
  接口方式:http post
  接口:getPoint.php
  返回数据:"arg1,arg2" arg1为已经点名学生，arg2为未点名学生

  版本2 更新
  接口:getPoint.php
  返回数据:"arg1,arg2" arg1为已经点名学生，arg2为未点名学生
  传入数据:{"pointTime":"1234566723"}
  测试地址:http://192.168.16.115/openapi/om_html5/getPoint.php?pointTime=1234566723
 */
//error_reporting(E_ERROR | E_WARNING | E_PARSE);
@error_reporting(0);
@set_time_limit(0);
@set_magic_quotes_runtime(0);
@ini_set('memory_limit', '512M');
$whiteboard_config_array = array();
$pointTime = isset($_REQUEST['pointTime']) ? $_REQUEST['pointTime'] : '';
$room_id = isset($_REQUEST['roomId']) ? $_REQUEST['roomId'] : '';
$sn_group_id = isset($_REQUEST['sn_group_id']) ? $_REQUEST['sn_group_id'] : '';
//ini_set("display_errors", "On");
//error_reporting(E_ALL);
if ($pointTime) {
    //DEBUG 解析白板配置文件
    $isp = isset($_REQUEST['isp']) && !empty($_REQUEST['isp']) ? $_REQUEST['isp'] : ''; //运营商编号 1 电信 2 移动 3 联通
    if (empty($isp)) {
        $isp = 1;
    }
    $whiteboard_config_array = parse_ini_file("../../config/room/config_whiteboard_" . $isp . ".ini", false);
    require '../../source/class/memory/memory_driver_redis_multi.php';
    require '../../config/config_global.php';
    $config_redis = array();
    $config_redis['master'] = array(
        array('host' => $whiteboard_config_array['MEMORY_REDIS_MASTER_SERVER'],
            'port' => $whiteboard_config_array['MEMORY_REDIS_MASTER_PORT'],
            'auth' => $whiteboard_config_array['MEMORY_REDIS_MASTER_AUTH'],
            'db' => $whiteboard_config_array['MEMORY_REDIS_MASTER_DB'],
            'pconnect' => $whiteboard_config_array['MEMORY_REDIS_MASTER_PCONNECT'],
            'timeout' => $whiteboard_config_array['MEMORY_REDIS_MASTER_TIMEOUT']
        )
    );
    $config_redis['slave'] = array(
        array('host' => $whiteboard_config_array['MEMORY_REDIS_SLAVE_SERVER'],
            'port' => $whiteboard_config_array['MEMORY_REDIS_MASTER_PORT'],
            'auth' => $whiteboard_config_array['MEMORY_REDIS_MASTER_AUTH'],
            'db' => $whiteboard_config_array['MEMORY_REDIS_MASTER_DB'],
            'pconnect' => $whiteboard_config_array['MEMORY_REDIS_MASTER_PCONNECT'],
            'timeout' => $whiteboard_config_array['MEMORY_REDIS_MASTER_TIMEOUT']
        )
    );
    //DEBUG 初始化redis
    $redis = RedisClient::getInstance($config_redis);
    $point_num = $redis->get('point_num_' . $pointTime);
    if (!$point_num) {
        $point_num = 0;
    }
    $un_point_num = 0;
    if ($room_id) {
        $master_username = $_config['db']['1']['dbuser'];
        $master_userpass = $_config['db']['1']['dbpw'];
        $master_dbhost = $_config['db']['1']['dbhost'];
        $master_dbname = $_config['db']['1']['dbname'];
        $master_dbconn = mysql_connect($master_dbhost, $master_username, $master_userpass) or die("Unable to connect to the Master MySQL!");
        //选择一个需要操作的数据库
        mysql_select_db($master_dbname, $master_dbconn);
        $course_sql = "SELECT cm_id FROM " . $_config['db']['1']['tablepre'] . "course_hour WHERE ch_id='" . $room_id . "' LIMIT 1";
        $result = mysql_query($course_sql, $master_dbconn);
        $course_info = mysql_fetch_array($result);
        $group_sql = "SELECT cm_count FROM " . $_config['db']['1']['tablepre'] . "course_main WHERE cm_id='" . $course_info['cm_id'] . "' LIMIT 1";
        $result = mysql_query($group_sql, $master_dbconn);
        $row = mysql_fetch_array($result);
        $un_point_num = $row['cm_count'] - $point_num;
        $un_point_num = max(0, $un_point_num);
        mysql_close($master_dbconn);
    }
    $redis->close();
    echo $point_num . ',' . $un_point_num;
}